package org.afun.oldhand.start.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;

import org.afun.oldhand.R;
import org.afun.oldhand.base.BaseFragment;
import org.afun.oldhand.start.adapter.StartAdapter;
import org.afun.oldhand.start.fragment.StartFragment1;
import org.afun.oldhand.start.fragment.StartFragment2;
import org.afun.oldhand.start.fragment.StartFragment3;

import java.util.ArrayList;


public class StartActivity extends AppCompatActivity {

    ViewPager2 viewpager;
    private ArrayList<BaseFragment> fragments;
    private StartFragment1 startFragment1;
    private StartFragment2 startFragment2;
    private StartFragment3 startFragment3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        initPager();
    }

    private void initPager() {
        viewpager = findViewById(R.id.id_viewpager2);
        fragments = new ArrayList<>();
        startFragment1 = new StartFragment1();
        startFragment2 = new StartFragment2();
        startFragment3 = new StartFragment3();

        fragments.add(startFragment1);
        fragments.add(startFragment2);
        fragments.add(startFragment3);
        StartAdapter startAdapter = new StartAdapter(getSupportFragmentManager(),getLifecycle(),fragments);
        viewpager.setAdapter(startAdapter);
        viewpager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback(){
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                super.onPageScrollStateChanged(state);
            }
        });

    }
}